<?php

namespace Xin\Logger;

trait EnableTimePrintable
{
    /**
     * @var bool
     */
    protected $enableTimePrint = false;

    /**
     * 获取是否时间打印
     * @return bool
     */
    public function isEnableTimePrint(): bool
    {
        return $this->enableTimePrint;
    }

    /**
     * 设置是否时间打印
     * @param bool $enableTimePrint
     * @return void
     */
    public function setEnableTimePrint(bool $enableTimePrint): void
    {
        $this->enableTimePrint = $enableTimePrint;
    }

    /**
     * 启用时间打印
     * @return void
     */
    public function enableTimePrint(): void
    {
        $this->setEnableTimePrint(true);
    }

    /**
     * 获取时间打印信息
     * @return string
     */
    protected function getTimePrefix(): string
    {
        if ($this->isEnableTimePrint()) {
            return '[' . now()->format('Y-m-d H:i:s') . ']' . ' ';
        }

        return '';
    }
}
